<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="css/icons-extra.css" />
		<link href="css/mui.imageviewer.css" rel="stylesheet" />
		<style>
			html,
			body {
				height: 100%;
				margin: 0px;
				padding: 0px;
				overflow: hidden;
				-webkit-touch-callout: none;
				-webkit-user-select: none;
			}
			footer {
				position: fixed;
				width: 100%;
				height: 50px;
				min-height: 50px;
				border-top: solid 1px #bbb;
				left: 0px;
				bottom: 0px;
				overflow: hidden;
				padding: 0px 50px;
				background-color: #fafafa;
			}
			.footer-left {
				position: absolute;
				width: 50px;
				height: 50px;
				left: 0px;
				bottom: 0px;
				text-align: center;
				vertical-align: middle;
				line-height: 100%;
				padding: 12px 4px;
			}
			.footer-right {
				position: absolute;
				width: 50px;
				height: 50px;
				right: 0px;
				bottom: 0px;
				text-align: center;
				vertical-align: middle;
				line-height: 100%;
				padding: 12px 5px;
				display: inline-block;
			}
			.footer-center {
				height: 100%;
				padding: 5px 0px;
			}
			.footer-center [class*=input] {
				width: 100%;
				height: 100%;
				border-radius: 5px;
			}
			.footer-center .input-text {
				background: #fff;
				border: solid 1px #ddd;
				padding: 10px !important;
				font-size: 16px !important;
				line-height: 18px !important;
				font-family: verdana !important;
				overflow: hidden;
			}
			.footer-center .input-sound {
				background-color: #eee;
			}
			.mui-content {
				height: 100%;
				padding: 44px 0px 50px 0px;
				overflow: auto;
				background-color: #eaeaea;
			}
			
			.msg-item {
				padding: 8px;
				clear: both;
			}
			.msg-item .mui-item-clear {
				clear: both;
			}
			.msg-item .msg-user {
				width: 38px;
				height: 38px;
				border: solid 1px #d3d3d3;
				display: inline-block;
				background: #fff;
				border-radius: 3px;
				vertical-align: top;
				text-align: center;
				float: left;
				padding: 3px;
				color: #ddd;
			}
			
			.msg-item .msg-user-img{
				width: 38px;
				height: 38px;
				display: inline-block;
				border-radius: 3px;
				vertical-align: top;
				text-align: center;
				float: left;
				color: #ddd;
			}
			
			.msg-item .msg-content {
				display: inline-block;
				border-radius: 5px;
				border: solid 1px #d3d3d3;
				background-color: #FFFFFF;
				color: #333;
				padding: 8px;
				vertical-align: top;
				font-size: 15px;
				position: relative;
				margin: 0px 8px;
				max-width: 75%;
				min-width: 35px;
				float: left;
			}
			.msg-item .msg-content .msg-content-inner {
				overflow-x: hidden;
			}
			.msg-item .msg-content .msg-content-arrow {
				position: absolute;
				border: solid 1px #d3d3d3;
				border-right: none;
				border-top: none;
				background-color: #FFFFFF;
				width: 10px;
				height: 10px;
				left: -5px;
				top: 12px;
				-webkit-transform: rotateZ(45deg);
				transform: rotateZ(45deg);
			}
			.msg-item-self .msg-user,
			.msg-item-self .msg-content {
				float: right;
			}
			.msg-item-self .msg-content .msg-content-arrow {
				left: auto;
				right: -5px;
				-webkit-transform: rotateZ(225deg);
				transform: rotateZ(225deg);
			}
			.msg-item-self .msg-content,
			.msg-item-self .msg-content .msg-content-arrow {
				background-color: #4CD964;
				color: #fff;
				border-color: #2AC845;
			}
			footer .mui-icon {
				color: #000;
			}
			footer .mui-icon:active {
				color: #007AFF !important;
			}
			footer .mui-icon-paperplane:before {
				content: "发送";
			}
			footer .mui-icon-paperplane {
				/*-webkit-transform: rotateZ(45deg);
				transform: rotateZ(45deg);*/
				
				font-size: 16px;
				word-break: keep-all;
				line-height: 100%;
				padding-top: 6px;
				color: rgba(0, 135, 250, 1);
			}
			#msg-sound {
				-webkit-user-select: none !important;
				user-select: none !important;
			}
			.rprogress {
				position: absolute;
				left: 50%;
				top: 50%;
				width: 140px;
				height: 140px;
				margin-left: -70px;
				margin-top: -70px;
				background-image: url(../images/arecord.png);
				background-repeat: no-repeat;
				background-position: center center;
				background-size: 30px 30px;
				background-color: rgba(0, 0, 0, 0.7);
				border-radius: 5px;
				display: none;
				-webkit-transition: .15s;
			}
			.rschedule {
				background-color: rgba(0, 0, 0, 0);
				border: 5px solid rgba(0, 183, 229, 0.9);
				opacity: .9;
				border-left: 5px solid rgba(0, 0, 0, 0);
				border-right: 5px solid rgba(0, 0, 0, 0);
				border-radius: 50px;
				box-shadow: 0 0 15px #2187e7;
				width: 46px;
				height: 46px;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -23px;
				margin-top: -23px;
				-webkit-animation: spin 1s infinite linear;
				animation: spin 1s infinite linear;
			}
			.r-sigh{
				display: none;
				border-radius: 50px;
				box-shadow: 0 0 15px #2187e7;
				width: 46px;
				height: 46px;
				position: absolute;
				left: 50%;
				top: 50%;
				margin-left: -23px;
				margin-top: -23px;
				text-align: center;
				line-height: 46px;
				font-size: 40px;
				font-weight: bold;
				color: #2187e7;
			}
			.rprogress-sigh{
				background-image: none !important;
			}
			.rprogress-sigh .rschedule{
				display: none !important;
			}
			.rprogress-sigh .r-sigh{
				display: block !important;
			}
			.rsalert {
				font-size: 12px;
				color: #bbb;
				text-align: center;
				position: absolute;
				border-radius: 5px;
				width: 130px;
				margin: 5px 5px;
				padding: 5px;
				left: 0px;
				bottom: 0px;
			}
			@-webkit-keyframes spin {
				0% {
					-webkit-transform: rotate(0deg);
				}
				100% {
					-webkit-transform: rotate(360deg);
				}
			}
			@keyframes spin {
				0% {
					transform: rotate(0deg);
				}
				100% {
					transform: rotate(360deg);
				}
			}
			#h {
				background: #fff;
				border: solid 1px #ddd;
				padding: 10px !important;
				font-size: 16px !important;
				font-family: verdana !important;
				line-height: 18px !important;
				overflow: visible;
				position: absolute;
				left: -1000px;
				right: 0px;
				word-break: break-all;
				word-wrap: break-word;
			}
			.cancel {
				background-color: darkred;
			}
			.title {
				margin: 20px 15px 10px;
				color: #6d6d72;
				font-size: 15px;
			}
			
			.right {
				position: absolute;
				right: 3px;
				font-size: 6px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">会话</h1>
		</header>
		<div class="mui-content">
			
			<ul id="msg-list" class="mui-table-view">
				
				
				<!--联系群组-->
				
			
			</ul>
		</div>
	</body>
	
    	<script src="js/mui.min.js"></script>
   		
	<script>
		
		var Chat = {};
		
		var personList=new Array(); //定义一数组
		var showList= new Array(); //定义一数组
		
		//var show="";
		//var show2="";
		var toShow="";
		var read=[];
		var read2=[];
		var n=0;
		
		var userid=localStorage.getItem("loginName");
        Chat.socket = null;
		//Chat.initialize();
        Chat.connect = (function (host) {
            if ('WebSocket' in window) {
                Chat.socket = new WebSocket(host);
            } else if ('MozWebSocket' in window) {
                Chat.socket = new MozWebSocket(host);
            } else {
                //console.log('Error: WebSocket is not supported by this browser.');
                return;
            }
		
		

            Chat.socket.onopen = function () {
                //console.log('Info: WebSocket connection opened.');
                
                       
                    	
                
            };

			
			
            Chat.socket.onclose = function () {
                
                //console.log('Info: WebSocket closed.');
                
            };
			
            Chat.socket.onmessage = function (message) {
            	//console.log(message.data);
            	var strs= new Array(); //定义一数组 
				strs=message.data.split(","); //字符分割 
				for (i=0;i<strs.length ;i++ ) 
				{ 
					
				}
				
				
				if(strs[3]=='qun'){
				mui.ajax({
							type: "post",
							url: "http://113.71.26.27:8080/tpl/phone/getPhoneImg",
							async: true,
							data: {
								loginName: strs[0]
							},
							dataType: "json",
							timeout: 3000,
							crossDomain: true,
							success: function(data) {
								
								if(strs[1]=='text'){
									n++;
            					var time=document.getElementById("time");
      							var text=document.getElementById("text");
            					var nowtime=getNowFormatDate();
            					time.innerHTML=nowtime;
            					text.innerHTML=data.name+":"+strs[2];
            					var num=document.getElementById("num");
								num.innerHTML=n;
            				}else if(strs[1]=='photo'){
            					n++;
			            		var time=document.getElementById("time");
       							var text=document.getElementById("text");
			            		var nowtime=getNowFormatDate();
			            		time.innerHTML=nowtime;
			            		text.innerHTML=data.name+":"+'[图片]';
			            		var num=document.getElementById("num");
								num.innerHTML=n;
			            	}
								
               			},
							error: function(xhr, type, errorThrown) {
								plus.nativeUI.toast(errorThrown);
							}
						});
            }else if(strs[3]=='person'){
            	
            	
            	
            	mui.ajax({
							type: "post",
							url: "http://113.71.26.27:8080/tpl/phone/getPhoneImg",
							async: true,
							data: {
								loginName: strs[2]
							},
							dataType: "json",
							timeout: 2000,
							crossDomain: true,
							success: function(data) {
							
							
							
							if(personList==null){
								//personList[0]="110";
								var nowtime=getNowFormatDate();
								var UTFName=encodeURI(encodeURI(data.name));//防止中文乱码
            				var photoUrl="http://113.71.26.27:8080/tpl/public/uploadImage/peopleLogo/"+data.imgUrl;
            		
					var show="<li id='"+strs[2]+"' class='mui-table-view-cell mui-media'>"
						+"<a href='single-chat2.html?firendsId="+strs[2]+"&&firendsName="+UTFName+"' class='mui-navigate-right'>"
							+"<img style='width:40px;height:40px;'  class='mui-media-object mui-pull-left' src='"+photoUrl+"'>"
					
						+"<div class='mui-media-body'>"
						
							+"<span class='mui-tab-label mui-slider-handle ' >"+data.name+"</span>"
							
							+"<span id='"+strs[2]+"1"+"' class='right'>"+nowtime+"</span>"
							+"<p id='"+strs[2]+"2"+"' class='mui-ellipsis'>"+strs[1]+"</p>"
						+"</div>"
					+"</a>"
							
					+"</li>";		
							Console.log(show);							
							personList.push(strs[2]);
							//存入
							
							
							}else{
							
							//读取
							
							var sure=checkSure(personList,strs[2]);
							//console.log(sure);
							if(sure){
								var nowtime=getNowFormatDate();
							var UTFName=encodeURI(encodeURI(data.name));//防止中文乱码
            				var photoUrl="http://113.71.26.27:8080/tpl/public/uploadImage/peopleLogo/"+data.imgUrl;
            		var show2="<li id='"+strs[2]+"' class='mui-table-view-cell mui-media'>"
						+"<a href='single-chat2.html?firendsId="+strs[2]+"&&firendsName="+UTFName+"' class='mui-navigate-right'>"
							+"<img style='width:40px;height:40px;'  class='mui-media-object mui-pull-left' src='"+photoUrl+"'>"
						
						
						+"<div class='mui-media-body'>"
						
							+"<span class='mui-tab-label mui-slider-handle ' >"+data.name+"</span>"
							
							+"<span id='"+strs[2]+"1"+"' class='right'>"+nowtime+"</span>"
							+"<p id='"+strs[2]+"2"+"' class='mui-ellipsis'>"+strs[1]+"</p>"
						+"</div>"
					+"</a>"
							
					+"</li>";
								
						
							Console.log(show2);
							personList.push(strs[2]);	
							//console.log(read);
							//存入
							//localStorage.setItem('key',JSON.stringify(read));
							//localStorage.setItem('pshow2',show2);
							}
							else{
									
							if(strs[0]=='text'){
								
								
							var t=document.getElementById(strs[2]+"2");
							t.innerHTML=strs[1];
							
							var t2=document.getElementById(strs[2]+"1");
							var nowtime2=getNowFormatDate();
							t2.innerHTML=nowtime2;
							
							
								
							
							
								
							}else{
								
							var t=document.getElementById(strs[2]);
							t.innerHTML='[图片]';
							
							var t2=document.getElementById(strs[2]+"1");
							var nowtime2=getNowFormatDate();
							t2.innerHTML=nowtime2;
							
							
								
							
							}
							
							
						}
            					
            				
						}	
               			},
							error: function(xhr, type, errorThrown) {
								plus.nativeUI.toast(errorThrown);
							}
						});
						
            		
            }
            
            
            }
        });

        
        Chat.close= function () {
          Chat.socket.onclose();  
        };
        
        /*function delPerson(id){
        	document.getElementById(id).addEventListener("tap",function(){
              var btnArray=['否','是'];
              var li=document.getElementById(id);
              mui.confirm("是否该删除该记录","警告",btnArray,function(e){
                  if(e.index==1)
                  {
                  	var ss=[];
                  	var list=JSON.parse(localStorage.getItem('key'));
                  	console.log(list);
                  	ss=delOne(list,id);
                  	localStorage.setItem('key',JSON.stringify(ss));
                  	console.log(ss);
                    li.parentNode.removeChild(li);
                     
                  }
                  else
                  {
                     
                  }
               });
           });
        };*/
		
		function checkSure(arr, obj) {
		  var i = arr.length;
		  while (i--) {
		    if (arr[i] === obj) {
		      return false ;
		    }
		  }
		  return true;
		};
		//删除记录
		function delOne(arr, obj) {
		  var i = arr.length;
		  var s=[];
		  while (i--) {
		    if (arr[i] == obj) {
		    	arr.splice(i, 1);
		    	
		    	
		    	
		      return s ;
		    }
		  }
		  s=arr;
		  return s;
		};
		
		mui.plusReady(function() {
			
      	 	checkWho();
      	 	 
      	 	 
			});
			
			function line(){
				
			//console.info("连接服务器");
      	 	Chat.connect('ws://113.71.26.27:8080/tpl/websocket/' + userid);//
				
			
			}
			
			//时间的格式转化
		function mmtime(time) {
			var newDate = new Date(time);
			var year = newDate.getFullYear();
			var month = (newDate.getMonth() + 1) < 10 ? "0" + (newDate.getMonth() + 1) : newDate.getMonth() + 1;
			var day = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate();
			var hours = newDate.getHours() < 10 ? "0" + newDate.getHours() : newDate.getHours();
			var minuts = newDate.getMinutes() < 10 ? "0" + newDate.getMinutes() : newDate.getMinutes();
			var seconds = newDate.getSeconds() < 10 ? "0" + newDate.getSeconds() : newDate.getSeconds();
			time =  month + "-" + day + " " + hours + ":" + minuts + ":" + seconds;
			return time;
		}
			var timeList=[];
			var timeList2=[];
		//监听公告变化	
		function getGongGao(){
			
			mui.ajax({
							type: "post",
							url: "http://113.71.26.27:8080/tpl/share1/ANotice",
							async: true,
							data: {},
							dataType: "json",
							timeout: 2000,
							crossDomain: true,
							success: function(data) {
								//console.log('响应成功！');
								
								var time2=document.getElementById("time2");
								
								time2.innerHTML=mmtime(data.createDate);
								var gtext=document.getElementById("gtext");
								gtext.innerHTML=data.title;
								
							
							},
							error: function(xhr, type, errorThrown) {
								plus.nativeUI.toast(errorThrown);
							}
					});
		    }
			
			
			
			
		 var Console = {};
		var messageList="";
        Console.log = (function (message) {
        	
        	messageList+=message;
            var console = document.getElementById('msg-list');
          
           
            if(message!=null){
            	 console.innerHTML = messageList;
            	// console.appendChild(p);
            
            }
           
            
        });
			
		//获取当前时间	
		function getNowFormatDate() {
		    var date = new Date();
		    var seperator1 = "-";
		    var seperator2 = ":";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate =   month + seperator1 + strDate
		            + " " + date.getHours() + seperator2 + date.getMinutes();
		    return currentdate;
		}	
		
		//验证是否是员工
		function checkWho() {
			
			
				var network=true;
				if(mui.os.plus) {
							mui.plusReady(function() {
								if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
									network = false;
								}
							});
						}
				if(network){
				
					mui.ajax({
						url:"http://113.71.26.27:8080/tpl/share1/checkWho",
						async:true,
						type: 'post',
						data:{
							loginName:userid
						},
						success:function(data) {
							//console.log("响应成功");
							//console.log("data:"+data);
						 
							if(data=="true"){
								//console.log("是员工");
						var text="<li class='mui-table-view-cell mui-media'>"
						+"<a href='more-chat.html'>"
								+"<img class='mui-media-object mui-pull-left' src='images/logo.png'>"
								
									+"<div class='mui-media-body'>"
									+"<span>微架构</span>"
								+"<span style='background-color:red ;' id='num' class='mui-badge right'>0</span>"
									+"<br/>"
									
									
									+"<span id='time' class='right'></span>"
									+"<p id='text' class='mui-ellipsis'></p>"
									+"</div>"
								+"</a></li>";
						var text2="<li class='mui-table-view-cell mui-media'>"
						+"<a href='noticeList2.html'>"
								
								+"<img class='mui-media-object mui-pull-left' src='images/logo2.png'>"
									+"<div class='mui-media-body'>"
									+"<span>公告</span>"
									+"<span id='time2' class='right'></span>"
									+"<p id='gtext' class='mui-ellipsis'></p>"
									+"</div>"
								+"</a></li>";		
							Console.log(text);
							Console.log(text2);
							
							
							getGongGao();//监听公告变化
							line();
							setTimeout("line()",6000);
      	 					setInterval("getGongGao()",60000);
							}else{
								
								//console.log("非员工");
								Console.log("<center class='center'>你还没加入企业</center>");
								
						 
							}
						},
						error: function(xhr, type, errorThrown) {
									plus.nativeUI.toast(errorThrown);
								}
					});
				}else{
					mui.toast("当前网络不给力，请稍后再试...");
				}

		}
		
		
			
	</script>
</html>